import BaseModel from './BaseModel'
import _ from 'lodash'
import DataModel from './';

export default class GeneralModel extends BaseModel {
  static type = 'general.model';

  constructor(data = null) {
    super(data);
    if (data !== null) {
      this.model(data);
    }
  }


  model(data) {
    for (let property of _.keys(data)) {
      let dataItem = data[property];
      if (dataItem instanceof Object) {
        if (dataItem.hasOwnProperty('type') && DataModel.hasModel(dataItem.type)) {
          this[property] = DataModel.buildModel(dataItem.type, dataItem);
        } else {
          this[property] = new GeneralModel(dataItem);
        }
        continue;
      }
      this[property] = dataItem;
    }
  }


}
